package com.gitee.feizns.v8.rander;

import com.gitee.feizns.utils.StringUtils;
import lombok.Data;

/**
 * @author feizns
 * @since 2019/8/13
 */
@Data
public class PackageConfig {

    static com.gitee.feizns.config.java.PackageConfig DEFAULT = new com.gitee.feizns.config.java.PackageConfig("");

    /**
     * 前缀
     */
    private String prefix;

    /**
     * 控制器包名
     */
    private String controller = "web.controller";

    /**
     * 业务包
     */
    private String service = "service";

    /**
     * mapper
     */
    private String mapper = "mapper";

    /**
     * 实体包
     */
    private String pojo = "domain.pojo";

    /**
     * 接收对象
     */
    private String ao = "domain.ao";

    /**
     * 响应对象
     */
    private String vo = "domain.vo";

    /**
     * 枚举包
     */
    private String enums = "domain.enums";

    /**
     * 错误包
     */
    private String error = "domain.error";

    /**
     * 公共配置包
     */
    private String config = "commons.config";

    /**
     * globalId
     */
    private String groupId;

    /**
     * artifactId
     */
    private String artifactId;

    /**
     * 版本
     */
    private String version = "0.0.1-SNAPSHOT";

    /**
     * 打包方式
     */
    private String packing = "jar";

    public String getController() {
        return StringUtils.concat(".", prefix, controller);
    }

    public String getService() {
        return StringUtils.concat(".", prefix, service);
    }

    public String getMapper() {
        return StringUtils.concat(".", prefix, mapper);
    }

    public String getPojo() {
        return StringUtils.concat(".", prefix, pojo);
    }

    public String getAo() {
        return StringUtils.concat(".", prefix, ao);
    }

    public String getVo() {
        return StringUtils.concat(".", prefix, vo);
    }

    public String getEnums() {
        return StringUtils.concat(".", prefix, enums);
    }

    public String getError() {
        return StringUtils.concat(".", prefix, error);
    }

    public String getConfig() {
        return StringUtils.concat(".", prefix, config);
    }

    public String getGroupId() {
        if ( groupId == null ) {
            int last = prefix.lastIndexOf(".");
            return last != -1 ? prefix.substring(0, last) : prefix;
        }
        return groupId;
    }

    public String getArtifactId() {
        if ( artifactId == null ) {
            int last = prefix.lastIndexOf(".");
            return last != -1 ? prefix.substring(last + 1) : prefix;
        }
        return artifactId;
    }

    public PackageConfig(String prefix) {
        this.prefix = prefix;
    }

    public PackageConfig() {
        this.prefix = "";
    }

}
